<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            height: 2000px;
            width: 100%;
            border: 2px solid red;
        }
        header{
            height: 150px;
        }
        nav{
            width: 100%;
            height: 60px;
            background-color: skyblue;
        }
       
    </style>
</head>
<body>
    <div>
        <header></header>
         <nav></nav>
    </div>
    
</body>
</html>
<script src="lib/jquery.min.js"></script>
<script>
      $(()=>{

     //给整个文档绑定滚动事件
      $(document).scroll(function(){
          let val = $(this).scrollTop();
          console.log(val);
          if(val>=210){
            $("nav").css({"position":"fixed","left":"0px","top":"0px"})
          }else{
            $("nav").css({"position":"static"})

          }
     }) 
      
    
    });

</script>

